﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaskelot.Services.Model;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.Mapping
{
    public static class BlankettExtensions
    {
        public static DataContracts.Blankett ToContract(this Blankett entity)
        {
            DataContracts.Blankett b = new DataContracts.Blankett();

            CopyFromEntity(entity, b, false);

            return b;
        }

        public static DataContracts.Blankett ToMinimalContract(this Blankett entity)
        {
            DataContracts.Blankett b = new DataContracts.Blankett();

            CopyFromEntity(entity, b, true);

            return b;
        }

        public static Blankett ToEntity(this DataContracts.Blankett b)
        {
            Blankett entity = new Blankett();

            CopyToEntity(b, entity);

            return entity;
        }

        public static void UpdateEntity(this Blankett entity, DataContracts.Blankett blankett)
        {
            CopyToEntity(blankett, entity);
        }

        private static void CopyFromEntity(Blankett from, DataContracts.Blankett to, bool minimal)
        {
            to.Id = from.Id;
            to.ValId = from.ValId;
            to.Andrad = from.Andrad;
            to.AndradAv = from.AndradAv;
            to.Skapad = from.Skapad;
            to.SkapadAv = from.SkapadAv;
            to.Namn = from.Namn;
            to.Typ = (DataContracts.BlankettTyp)from.BlankettTyp;

            return;
        }

        private static void CopyToEntity(DataContracts.Blankett from, Blankett to)
        {
            to.Id = from.Id;
            to.ValId = from.ValId;
            to.Andrad = from.Andrad;
            to.AndradAv = from.AndradAv;
            to.Skapad = from.Skapad;
            to.SkapadAv = from.SkapadAv;
            to.Namn = from.Namn;
            to.BlankettTyp = (int)from.Typ;
        }
    }
}
